package com.cat.bitOperation;

import java.util.HashMap;
import java.util.HashSet;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/longest-subarray-with-maximum-bitwise-and/
 * @create 2025/8/22 14:36
 * @since JDK17
 */

public class Solution12 {
    public int longestSubarray(int[] nums) {
        int max = -1, ans = 0, n = nums.length;
        for (int num : nums) {
            max = Math.max(max, num);
        }
        for (int i = 0, j; i < n; i++) {
            if (nums[i] != max) {
                continue;
            }
            j = i;
            while (i < n && nums[i] == max) {
                i++;
            }
            ans = Math.max(ans, i - j);
        }
        return ans;
    }
}
